# -*- coding: utf-8 -*-
"""
Created on Wed Jul  5 22:15:03 2017

@author: Jocker

"""
#user_id_info{username:"",password:"",userid:""}-------hset----store userinfo--persistent
#user_id_pool(userid1,userid2,userid3)---------set----for useridcreator test---persistent
#user_name_pool{username1,username2,uusername3}-----set----for register test---persistent
#user_online_pool(userid1:session,userid2:session)-set--for onlineuser find-----temporary
#user_friendlist(userid:username,userid:username)--hset--for friendlist find---persistent
import time
import LOG as logfile
import datetime;  
import random;  
import threading
#log配置
log_path="../log/mqtt_log"
log= logfile.setlog("MQTT_SERVER",log_path)
#工具函数
def UserIdCreater(num):
    nowTime=datetime.datetime.now().strftime("%Y%m%d%H%M%S");#生成当前时间  
    randomNum=random.randint(0,100);#生成的随机整数n，其中0<=n<=100  
    if randomNum<=10:  
        randomNum=str(0)+str(randomNum);  
    uniqueNum=str(nowTime)+str(randomNum);
    userid=uniqueNum[0-num-1:-1]
    return userid 

def HashCodeCreator(num):
    code_list = []
    for i in range(10): # 0-9数字
        code_list.append(str(i))
    for i in range(65, 91): # A-Z
        code_list.append(chr(i))
    for i in range(97, 123): # a-z
        code_list.append(chr(i))

    myslice = random.sample(code_list, num)  # 从list中随机获取6个元素，作为一个片断返回
    verification_code = ''.join(myslice) # list to string
    # print code_list
    # print type(myslice)
    return verification_code

def GetTiemString():
    return time.strftime('%Y-%m-%d',time.localtime(time.time()))
   
def GetLog():
    return log